JavaScript

DatefromObject Method

Syntax

Date.fromObject(object,settings)

Arguments

objectobjectarray

The object or array containing the date values.

settingsobject

The settings for combing the date value from disparate parts of the object.

datestringarray

The path to a date or string variable in the object containing the full or partial date value. If the path is to a string variable then the format for converting the string into a valid date can be appended using a ":". For example "person.dob:MM/dd/yyyy". See Date.toFormat and A5.u.object.get.

timestringarray

The path to a time string value in the object. See A5.u.object.get and Date.setClock.

yearstringarray

The path to a year value in the object. See A5.u.object.get.

monthstringarray

The path to a month value in the object. See A5.u.object.get.

daystringarray

The path to a day of the month value in the object. See A5.u.object.get.

hoursstringarray

The path to a hours value in the object. See A5.u.object.get.

minutesstringarray

The path to a minutes value in the object. See A5.u.object.get.

secondsstringarray

The path to a seconds value in the object. See A5.u.object.get.

millisecondsstringarray

The path to a milliseconds value in the object. See A5.u.object.get.

Description

Extension to the native date variable to set the date variable to the value of one or more parts of an object or array.

Discussion

The Date.fromObject method sets the value of the date to one made up of one or more parts of the passed in object. This can be useful when a date is split into multiple parts when stored in an object or array.

Example

var obj = {dob: {year: 1981, month: 4, day: 15, time: '7:15pm'}};
var d = new Date();
d.fromObject(obj,{
	year: 'dob.year',
	month: 'dob.month',
	day: 'dob.day',
	time: 'dob.time'
});
// d = Date(1981,3,15,19,15)